<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Pager
 *
 * @author neozilon
 */
class Nosql_Util_Pager {

    public static function getPager($currentPage, $numResults, $resultsPerPage, $numberOfPagesToShow = 3) {

        $totalPages = intval($numResults / $resultsPerPage);
        $totalPages += ( ($numResults % $resultsPerPage) > 0 )? 1 : 0;

        if ( ($currentPage-1)>0 ){
            $result['prevPage'] = $currentPage-1;
        }
        if ( ($currentPage+1)<= $totalPages ){
            $result['nextPage'] = $currentPage+1;
        }

        $pages = array();
        for($i=($currentPage-$numberOfPagesToShow); $i <= ($currentPage+3); $i++ ){
            if ($i>0 && $i<= $totalPages){
                $pages[] = $i;
            }
        }

        if ($currentPage > 1){
            $result['firstPage'] = 1;
        }
        if ($currentPage < $totalPages){
            $result['lastPage'] = $totalPages;
        }
        $result['currentPage'] = $currentPage;
        $result['pages'] = $pages;

        return $result;
    }
    
}
